var t = getApp(),
    a = t.requirejs("core"),
    o = (t.requirejs("jquery"), t.requirejs("foxui"),
        t.requirejs("wxParse/wxParse")),
    e = 0;

Page({
    data: {
        goods_id: 0,
        advHeight: 1,
        data: {},
        time: [],
        goodsid: null, //支付成功返回id
        isShows: false,
        isShow: false,
        list: [],
        setIntervaltime: ""
    },
    imageLoad: function (t) {
        var a = t.detail.height,
            o = t.detail.width,
            e = Math.floor(750 * a / o);
        a == o ? this.setData({
            advHeight: 750
        }) : this.setData({
            advHeight: e
        });
    },
    onLoad: function (e) {
        var i = this;
        t.getCache("isIpx") ? i.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar"
        }) : i.setData({
            isIpx: !1,
            iphonexnavbar: ""
        });
        var s = e.id;
        this.setData({
            goods_id: s,
        }), a.post("groups.goods", {
            id: s
        }, function (t) {
            console.log(t, 222);
            if (t.error == "达到人数上限") {
                wx.showToast({
                    title: "助力完成",
                    icon: "none",
                })
                setTimeout(() => {
                    wx.navigateBack({
                        delta: 0,
                    })
                }, 2000)
            } else {
                i.setData({
                    data: t.data
                }), o.wxParse("wxParseData", "html", t.data.content, i, "0");
                i.setData({
                    setIntervaltime: setInterval(() => {
                        i.countDown(i.data.data.endtime, i.data.data.createtime)
                        // (this.countDown(1609473600,1637207519))
                    }, 1000)
                })
            }
        });
        a.post("groups.goods.fight_groups", {
            id: this.data.goods_id
        }, ((el) => {
            this.setData({
                list: el
            })
        }))
    },
    guanbi() {
        this.setData({
            isShow: false,
            isShows: false
        })
    },
    toast() {
        this.setData({
            isShow: true
        })
    },
    joinTeam: function (o) {
        t.checkAuth();
        wx.setStorageSync('goodsid', this.data.data.id)
        var e = this;
        wx.getSetting({
            success: function (t) {
                if (getApp().getCache("userinfo_openid")) {
                    var d = a.pdata(o).type,
                        s = a.pdata(o).op;
                    if (e.setData({
                            optionarr: [],
                            selectSpecsarr: []
                        }), "creat" == s ? e.setData({
                            op: "creat"
                        }) : e.setData({
                            op: ""
                        }), "ladder" == d) {
                        var i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            0 == t.error ? e.setData({
                                layershow: !0,
                                chosenum: !0
                            }) : wx.showToast({
                                title: t.message,
                                icon: "none",
                                duration: 2e3
                            });
                        });
                    } else if (0 == e.data.data.more_spec) {
                        i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            "creat" == s ? wx.navigateTo({
                                url: "../confirm/index?type=groups&id=" + i + "&heads=1"
                            }) : a.get("groups.goods.check_tuan", {
                                id: i,
                                type: "group"
                            }, function (t) {
                                if (e.data.list.other.length > 0) {
                                    wx.showModal({
                                        cancelColor: 'cancelColor',
                                        content: "此商品已有助力",
                                        confirmText: "去助力",
                                        cancelText: "自己开团",
                                        cancelColor: '#000000',
                                        confirmColor: '#000000',
                                        success(res) {
                                            if (res.confirm) {
                                                wx.navigateTo({
                                                    url: "../jointeam/index?id=" + i
                                                });
                                            } else if (res.cancel) {
                                                wx.navigateTo({
                                                    url: "../confirm/index?type=groups&id=" + i + "&heads=1"
                                                })
                                            }
                                        }
                                    })
                                }
                            })
                        });
                    } else {
                        i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            0 == t.error ? (a.get("groups.goods.get_spec", {
                                id: i
                            }, function (t) {
                                console.log(t);
                                e.setData({
                                    spec: t.data
                                });
                            }), e.setData({
                                layershow: !0,
                                options: !0
                            })) : wx.showToast({
                                title: t.message,
                                icon: "none",
                                duration: 2e3
                            });
                        });
                    }
                }
            }
        });
    },
    toast() {
        this.setData({
            isShow: true
        })
    },
    countDown: function (t, a) {
        var o = parseInt(Date.now() / 1e3),
            s = parseInt((t > o ? t : a) - o),
            i = Math.floor(s / 86400),
            d = Math.floor((s - 24 * i * 60 * 60) / 3600),
            n = Math.floor((s - 24 * i * 60 * 60 - 3600 * d) / 60),
            r = Math.floor(s - 24 * i * 60 * 60 - 3600 * d - 60 * n);
        0 == i && 0 == d && 0 == n && 0 == r && this.get_details(this.data.teamid);
        var u = [i, d, n, r];
        this.setData({
            time: u
        });
    },
    singlebuy: function (t) {
        var o = this;
        a.post("groups/goods/goodsCheck", {
            id: o.data.goods_id,
            type: "single"
        }, function (t) {
            if (1 != t.error)
                if (0 == o.data.data.more_spec) wx.navigateTo({
                    url: "../confirm/index?id=" + o.data.goods_id + "&type=single"
                });
                else {
                    o.setData({
                        layershow: !0,
                        options: !0
                    }), o.setData({
                        optionarr: [],
                        selectSpecsarr: []
                    });
                    var e = o.data.data.id;
                    a.get("groups.goods.get_spec", {
                        id: e
                    }, function (t) {
                        o.setData({
                            spec: t.data
                        });
                    }), o.setData({
                        layershow: !0,
                        options: !0
                    });
                }
            else a.alert(t.message);
        });
    },
    close: function () {
        this.setData({
            layershow: !1,
            options: !1
        });
    },
    specsTap: function (t) {
        e++;
        var o = this,
            i = o.data.spec,
            s = a.pdata(t).spedid,
            n = a.pdata(t).id,
            d = a.pdata(t).specindex;
        a.pdata(t).idx;
        i[d].item.forEach(function (t, a) {
            t.id == n ? i[d].item[a].status = "active" : i[d].item[a].status = "";
        }), o.setData({
            spec: i
        });
        var r = o.data.optionarr,
            p = o.data.selectSpecsarr;
        1 == e ? (r.push(n), p.push(s)) : p.indexOf(s) > -1 ? r.splice(d, 1, n) : (r.push(n),
            p.push(s)), o.data.optionarr = r, o.data.selectSpecsarr = p, a.post("groups.goods.get_option", {
            spec_id: o.data.optionarr,
            groups_goods_id: o.data.goods_id
        }, function (t) {
            o.setData({
                optiondata: t.data
            });
        });
    },
    buy: function (t) {
        var o = this,
            e = (a.pdata(t).op, o.data.goods_id),
            i = o.data.optiondata;
        o.data.optiondata ? i.stock > 0 ? wx.navigateTo({
            url: "../confirm/index?id=" + e + "&option_id=" + i.id + " &type=single",
            success: function () {
                o.setData({
                    layershow: !1,
                    chosenum: !1,
                    options: !1
                });
            }
        }) : wx.showToast({
            title: "库存不足",
            icon: "none",
            duration: 2e3
        }) : wx.showToast({
            title: "请选择规格",
            icon: "none",
            duration: 2e3
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {
        clearInterval(this.data.setIntervaltime)
    },
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function () {
        return {
            title: this.data.data.title
        };
    },
    check: function () {}
});